#--------------------------------------------------------------------
# Makefile for Kruununhaka basis set tool kit
# Insert compiler, flags etc.!
# Usually maximum optimization is ok
#--------------------------------------------------------------------

F95     = gfortran
CC	= gcc
FLAGS	= -Wall -O2 -g -floop-optimize -funroll-loops
LIBS    = -L/usr/lib64/atlas -llapack -latlas -lgsl

# Fortran compiler flags
FFLAGS	= $(FLAGS)
# C compiler flags
CFLAGS	= $(FLAGS)

#-------------- No changes should be necessary hereafter ----------------------

# Objective files to link
OBJ	= completeness_profile.o definitions.o error.o gslrand.o inout.o measure.o menu_contr.o menu.o menu_main.o menu_plot.o menu_prim.o menu_read.o menu_save.o optimize_contractions.o optimize_eventempered.o optimize_primitives.o overlap.o random.o resize.o sort.o textutil.o

# Name of executable
EXE	= kruna

default: all

all:	
	$(MAKE) -C build -f ../Makefile $(EXE)
	mv build/$(EXE) .

clean:
	-\rm -f $(EXE) build/*.o build/*.mod

$(EXE) : $(OBJ)
	$(F95) $(FFLAGS) -o $(EXE) $(OBJ) $(LIBS)

# Dependencies
textutil.o: definitions.o
error.o: textutil.o

completeness_profile.o: definitions.o error.o
contraction.o: definitions.o
inout.o: definitions.o error.o
measure.o: completeness_profile.o

menu.o: textutil.o
menu_contr.o: menu.o optimize_contractions.o
menu_plot.o: menu.o completeness_profile.o
menu_prim.o: menu.o optimize_eventempered.o optimize_primitives.o resize.o
menu_read.o: menu.o inout.o
menu_save.o: menu.o inout.o
menu_main.o: menu_read.o menu_prim.o menu_plot.o menu_save.o menu_contr.o

random.o: definitions.o
resize.o: definitions.o
sort.o: definitions.o

optimize_contractions.o: measure.o random.o
optimize_eventempered.o: measure.o random.o sort.o 
optimize_primitives.o: measure.o random.o sort.o 

# Look for source in
VPATH=../src

# Compilation rules
%.o: %.f
	$(F95) $(FFLAGS) -c $< -o $@
%.o: %.f90
	$(F95) $(FFLAGS) -c $< -o $@
%.o: %.c
	$(CC)  $(CFLAGS) -c $< -o $@

# Disable implicit rule that would want to generate objects from module files
%.o: %.mod
